package com.yjhb.android.sbz.v2.adapter

import android.content.Context
import android.graphics.Color
import android.view.View
import android.widget.TextView
import com.bumptech.glide.Glide
import com.yjhb.android.sbz.R
import com.yjhb.android.sbz.v2.entity.TaskRewardItem
import com.yjhb.android.sbz.view.drawable.NumberDrawable
import com.jojo.android.zxlib.base.BaseRecyclerAdapterV2


/**
 *  创建者 zx
 *  创建时间 2021/4/6 11:05
 */
class V2TaskRewardRankAdapter(context: Context) : BaseRecyclerAdapterV2<BaseRecyclerAdapterV2.BaseHolder, TaskRewardItem>(context) {

    override fun getLayoutId() = R.layout.item_reward_rank

    override fun onBindViewHolder(holder: BaseHolder, position: Int) {
        val markTv = holder.findViewById<TextView>(R.id.mark_iv)
        markTv.text = "${position + 1}"
        when (position) {
            0 -> markTv.setBackgroundResource(R.mipmap.gold_medal)
            1 -> markTv.setBackgroundResource(R.mipmap.silver_medal)
            2 -> markTv.setBackgroundResource(R.mipmap.bronze_medal)
            else -> {
                var drawable = markTv.background
                if (drawable == null || drawable !is NumberDrawable) {
                    drawable = NumberDrawable()
                    drawable.bgColor = Color.parseColor("#FF484D")
                    markTv.background = drawable
                }
                markTv.text = ""
                drawable.number = position + 1
            }
        }

        Glide.with(context)
                .load(entity.avatar)
                .error(R.mipmap.test_head)
                .into(holder.findViewById(R.id.head_iv))
        holder.findViewById<TextView>(R.id.nickname_tv).text = entity.nickName
        holder.findViewById<TextView>(R.id.money_tv).text = entity.reward
        holder.findViewById<TextView>(R.id.reward_tv).text = entity.money
    }


    override fun getHolder(v: View) = BaseHolder(v)
}